package kr.co.kiso.usr.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

public class ExceptionHandleResolver implements HandlerExceptionResolver {
	private Logger log = LoggerFactory.getLogger(this.getClass());

//	@Override
	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object obj, Exception exception) {

		log.debug(exception.toString());
		ModelAndView mav = new ModelAndView();
		if (exception instanceof RequiredLoginException) {
			// 로그인 필요

			RequiredLoginException re = (RequiredLoginException) exception;

			if (re.getUrl() != null) {
				//mav.clear();
				mav.setViewName("/dsmgr/index");
				mav.addObject("returnUrl",re.getUrl() );
			} else {
				mav.clear();
				mav.setViewName("redirect:/dsmgr/index.do");
			}
		} else {
			mav.setViewName("/error/500");
		}

		return mav;
	}

}
